<template>
  <div class="app-container">
    <div class="back-item">
      <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
        <el-form-item label="订单子单编号" prop="orderItemNo" v-if="showSearch">
          <el-input
              v-model="queryParams.orderItemNo"
              placeholder="请输入订单子单编号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="订单ID" prop="orderId" v-if="showSearch">
          <el-input
              v-model="queryParams.orderId"
              placeholder="请输入订单ID"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="支付单号" prop="payOrderNo" v-if="showSearch">
          <el-input
              v-model="queryParams.payOrderNo"
              placeholder="请输入支付单号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="客户" prop="customerId" v-if="showSearch">
          <el-input
              v-model="queryParams.customerId"
              placeholder="请输入客户"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="商品" prop="productId" v-if="showSearch">
          <el-input
              v-model="queryParams.productId"
              placeholder="请输入商品"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="规格Id" prop="goodsId" v-if="showSearch">
          <el-input
              v-model="queryParams.goodsId"
              placeholder="请输入规格Id"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="一级品类" prop="firstCategoryId" v-if="showSearch">
          <el-input
              v-model="queryParams.firstCategoryId"
              placeholder="请输入一级品类"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="二级品类" prop="secondCategoryId" v-if="showSearch">
          <el-input
              v-model="queryParams.secondCategoryId"
              placeholder="请输入二级品类"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="三级品类" prop="thirdCategoryId" v-if="showSearch">
          <el-input
              v-model="queryParams.thirdCategoryId"
              placeholder="请输入三级品类"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="商品名称" prop="productName" v-if="showSearch">
          <el-input
              v-model="queryParams.productName"
              placeholder="请输入商品名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="商品图" prop="productImg" v-if="showSearch">
          <el-input
              v-model="queryParams.productImg"
              placeholder="请输入商品图"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="成本价" prop="costPrice" v-if="showSearch">
          <el-input
              v-model="queryParams.costPrice"
              placeholder="请输入成本价"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="售价" prop="salePrice" v-if="showSearch">
          <el-input
              v-model="queryParams.salePrice"
              placeholder="请输入售价"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="购买数量" prop="buyNum" v-if="showSearch">
          <el-input
              v-model="queryParams.buyNum"
              placeholder="请输入购买数量"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="订单总结" prop="orderTotalMoney" v-if="showSearch">
          <el-input
              v-model="queryParams.orderTotalMoney"
              placeholder="请输入订单总结"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="优惠金额" prop="preMoney" v-if="showSearch">
          <el-input
              v-model="queryParams.preMoney"
              placeholder="请输入优惠金额"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="商品总价" prop="payProductMoney" v-if="showSearch">
          <el-input
              v-model="queryParams.payProductMoney"
              placeholder="请输入商品总价"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="优惠券金" prop="couponMoney" v-if="showSearch">
          <el-input
              v-model="queryParams.couponMoney"
              placeholder="请输入优惠券金"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="实付金额" prop="payMoney" v-if="showSearch">
          <el-input
              v-model="queryParams.payMoney"
              placeholder="请输入实付金额"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="购物金" prop="shopMoney" v-if="showSearch">
          <el-input
              v-model="queryParams.shopMoney"
              placeholder="请输入购物金"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="规格编码" prop="skuCode" v-if="showSearch">
          <el-input
              v-model="queryParams.skuCode"
              placeholder="请输入规格编码"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="邮费" prop="postagePrice" v-if="showSearch">
          <el-input
              v-model="queryParams.postagePrice"
              placeholder="请输入邮费"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="买家留言" prop="buyerMsg" v-if="showSearch">
          <el-input
              v-model="queryParams.buyerMsg"
              placeholder="请输入买家留言"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="供应商" prop="supplierId" v-if="showSearch">
          <el-input
              v-model="queryParams.supplierId"
              placeholder="请输入供应商"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="Search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button type="warning" icon="Refresh" size="mini" @click="resetQuery">重置</el-button>
          <el-button size="mini" @click="changSearch">{{showSearch?"常用条件":"所有条件"}}</el-button>
        </el-form-item>
      </el-form>
    </div>

    <div class="back-item">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
              type="primary"
              plain
              icon="Plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['mall:orderItem:add']"
          >新增
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
              type="success"
              plain
              icon="Edit"
              size="mini"
              :disabled="single"
              @click="handleUpdate"
              v-hasPermi="['mall:orderItem:edit']"
          >修改
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
              type="danger"
              plain
              icon="Delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['mall:orderItem:remove']"
          >删除
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
              type="warning"
              plain
              icon="Download"
              size="mini"
              :loading="exportLoading"
              @click="handleExport"
              v-hasPermi="['mall:orderItem:export']"
          >导出
          </el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="orderItemList"
          @selection-change="handleSelectionChange"
          @row-dblclick="handleDetails"
      >
        <el-table-column type="selection" width="55" align="center"/>
        <el-table-column label="订单子单ID" align="center" prop="orderItemId" v-if="columns[0].visible"/>
        <el-table-column label="订单子单编号" align="center" prop="orderItemNo" v-if="columns[1].visible"/>
        <el-table-column label="订单ID" align="center" prop="orderId" v-if="columns[2].visible"/>
        <el-table-column label="支付单号" align="center" prop="payOrderNo" v-if="columns[3].visible"/>
        <el-table-column label="客户" align="center" prop="customerId" v-if="columns[4].visible"/>
        <el-table-column label="商品" align="center" prop="productId" v-if="columns[5].visible"/>
        <el-table-column label="规格Id" align="center" prop="goodsId" v-if="columns[6].visible"/>
        <el-table-column label="一级品类" align="center" prop="firstCategoryId" v-if="columns[7].visible"/>
        <el-table-column label="二级品类" align="center" prop="secondCategoryId" v-if="columns[8].visible"/>
        <el-table-column label="三级品类" align="center" prop="thirdCategoryId" v-if="columns[9].visible"/>
        <el-table-column label="商品名称" align="center" prop="productName" v-if="columns[10].visible"/>
        <el-table-column label="商品图" align="center" prop="productImg" v-if="columns[11].visible"/>
        <el-table-column label="成本价" align="center" prop="costPrice" v-if="columns[12].visible"/>
        <el-table-column label="售价" align="center" prop="salePrice" v-if="columns[13].visible"/>
        <el-table-column label="购买数量" align="center" prop="buyNum" v-if="columns[14].visible"/>
        <el-table-column label="订单总结" align="center" prop="orderTotalMoney" v-if="columns[15].visible"/>
        <el-table-column label="优惠金额" align="center" prop="preMoney" v-if="columns[16].visible"/>
        <el-table-column label="商品总价" align="center" prop="payProductMoney" v-if="columns[17].visible"/>
        <el-table-column label="优惠券金" align="center" prop="couponMoney" v-if="columns[18].visible"/>
        <el-table-column label="实付金额" align="center" prop="payMoney" v-if="columns[19].visible"/>
        <el-table-column label="购物金" align="center" prop="shopMoney" v-if="columns[20].visible"/>
        <el-table-column label="商品规格" align="center" prop="goodsAttr" v-if="columns[21].visible"/>
        <el-table-column label="规格编码" align="center" prop="skuCode" v-if="columns[22].visible"/>
        <el-table-column label="评论状态" align="center" prop="commentStatus" v-if="columns[23].visible"/>
        <el-table-column label="状态" align="center" prop="status" v-if="columns[24].visible"/>
        <el-table-column label="发货方式 ( 0普通快递 1无需物流）" align="center" prop="deliveryType" v-if="columns[25].visible"/>
        <el-table-column label="邮费" align="center" prop="postagePrice" v-if="columns[26].visible"/>
        <el-table-column label="发票类型" align="center" prop="invoiceType" v-if="columns[27].visible"/>
        <el-table-column label="开票状态" align="center" prop="invoiceStatus" v-if="columns[28].visible"/>
        <el-table-column label="买家留言" align="center" prop="buyerMsg" v-if="columns[29].visible"/>
        <el-table-column label="供应商" align="center" prop="supplierId" v-if="columns[30].visible"/>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width"
            v-if="columns[33].visible"
        >
          <template #default="scope">
            <el-button
                size="mini"
                type="text"
                icon="Edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['mall:orderItem:edit']"
            >修改
            </el-button>
            <el-button
                size="mini"
                type="text"
                icon="Document"
                @click="handleDetails(scope.row)"
                v-hasPermi="['mall:orderItem:query']"
            >详情
            </el-button>
            <el-button
                size="mini"
                type="text"
                icon="Delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['mall:orderItem:remove']"
            >删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
      />
      <div class="line-magin"></div>
    </div>
    <!-- 添加或修改订单子单对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="orderItemForm" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="订单子单编号" prop="orderItemNo">
          <el-input v-model="form.orderItemNo" placeholder="请输入订单子单编号"/>
        </el-form-item>
        <el-form-item label="订单ID" prop="orderId">
          <el-input v-model="form.orderId" placeholder="请输入订单ID"/>
        </el-form-item>
        <el-form-item label="支付单号" prop="payOrderNo">
          <el-input v-model="form.payOrderNo" placeholder="请输入支付单号"/>
        </el-form-item>
        <el-form-item label="客户" prop="customerId">
          <el-input v-model="form.customerId" placeholder="请输入客户"/>
        </el-form-item>
        <el-form-item label="商品" prop="productId">
          <el-input v-model="form.productId" placeholder="请输入商品"/>
        </el-form-item>
        <el-form-item label="规格Id" prop="goodsId">
          <el-input v-model="form.goodsId" placeholder="请输入规格Id"/>
        </el-form-item>
        <el-form-item label="一级品类" prop="firstCategoryId">
          <el-input v-model="form.firstCategoryId" placeholder="请输入一级品类"/>
        </el-form-item>
        <el-form-item label="二级品类" prop="secondCategoryId">
          <el-input v-model="form.secondCategoryId" placeholder="请输入二级品类"/>
        </el-form-item>
        <el-form-item label="三级品类" prop="thirdCategoryId">
          <el-input v-model="form.thirdCategoryId" placeholder="请输入三级品类"/>
        </el-form-item>
        <el-form-item label="商品名称" prop="productName">
          <el-input v-model="form.productName" placeholder="请输入商品名称"/>
        </el-form-item>
        <el-form-item label="商品图" prop="productImg">
          <el-input v-model="form.productImg" placeholder="请输入商品图"/>
        </el-form-item>
        <el-form-item label="成本价" prop="costPrice">
          <el-input v-model="form.costPrice" placeholder="请输入成本价"/>
        </el-form-item>
        <el-form-item label="售价" prop="salePrice">
          <el-input v-model="form.salePrice" placeholder="请输入售价"/>
        </el-form-item>
        <el-form-item label="购买数量" prop="buyNum">
          <el-input v-model="form.buyNum" placeholder="请输入购买数量"/>
        </el-form-item>
        <el-form-item label="订单总结" prop="orderTotalMoney">
          <el-input v-model="form.orderTotalMoney" placeholder="请输入订单总结"/>
        </el-form-item>
        <el-form-item label="优惠金额" prop="preMoney">
          <el-input v-model="form.preMoney" placeholder="请输入优惠金额"/>
        </el-form-item>
        <el-form-item label="商品总价" prop="payProductMoney">
          <el-input v-model="form.payProductMoney" placeholder="请输入商品总价"/>
        </el-form-item>
        <el-form-item label="优惠券金" prop="couponMoney">
          <el-input v-model="form.couponMoney" placeholder="请输入优惠券金"/>
        </el-form-item>
        <el-form-item label="实付金额" prop="payMoney">
          <el-input v-model="form.payMoney" placeholder="请输入实付金额"/>
        </el-form-item>
        <el-form-item label="购物金" prop="shopMoney">
          <el-input v-model="form.shopMoney" placeholder="请输入购物金"/>
        </el-form-item>
        <el-form-item label="商品规格" prop="goodsAttr">
          <el-input v-model="form.goodsAttr" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="规格编码" prop="skuCode">
          <el-input v-model="form.skuCode" placeholder="请输入规格编码"/>
        </el-form-item>
        <el-form-item label="邮费" prop="postagePrice">
          <el-input v-model="form.postagePrice" placeholder="请输入邮费"/>
        </el-form-item>
        <el-form-item label="买家留言" prop="buyerMsg">
          <el-input v-model="form.buyerMsg" placeholder="请输入买家留言"/>
        </el-form-item>
        <el-form-item label="供应商" prop="supplierId">
          <el-input v-model="form.supplierId" placeholder="请输入供应商"/>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 订单子单详情对话框 -->
    <el-dialog class="detail-form" :title="title" v-model="open2" width="700px" append-to-body>
      <el-form ref="orderItemDetail" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="订单子单编号" prop="orderItemNo">
        {{ form.orderItemNo }}
      </el-form-item>
      <el-form-item label="订单ID" prop="orderId">
        {{ form.orderId }}
      </el-form-item>
      <el-form-item label="支付单号" prop="payOrderNo">
        {{ form.payOrderNo }}
      </el-form-item>
      <el-form-item label="客户" prop="customerId">
        {{ form.customerId }}
      </el-form-item>
      <el-form-item label="商品" prop="productId">
        {{ form.productId }}
      </el-form-item>
      <el-form-item label="规格Id" prop="goodsId">
        {{ form.goodsId }}
      </el-form-item>
      <el-form-item label="一级品类" prop="firstCategoryId">
        {{ form.firstCategoryId }}
      </el-form-item>
      <el-form-item label="二级品类" prop="secondCategoryId">
        {{ form.secondCategoryId }}
      </el-form-item>
      <el-form-item label="三级品类" prop="thirdCategoryId">
        {{ form.thirdCategoryId }}
      </el-form-item>
      <el-form-item label="商品名称" prop="productName">
        {{ form.productName }}
      </el-form-item>
      <el-form-item label="商品图" prop="productImg">
        {{ form.productImg }}
      </el-form-item>
      <el-form-item label="成本价" prop="costPrice">
        {{ form.costPrice }}
      </el-form-item>
      <el-form-item label="售价" prop="salePrice">
        {{ form.salePrice }}
      </el-form-item>
      <el-form-item label="购买数量" prop="buyNum">
        {{ form.buyNum }}
      </el-form-item>
      <el-form-item label="订单总结" prop="orderTotalMoney">
        {{ form.orderTotalMoney }}
      </el-form-item>
      <el-form-item label="优惠金额" prop="preMoney">
        {{ form.preMoney }}
      </el-form-item>
      <el-form-item label="商品总价" prop="payProductMoney">
        {{ form.payProductMoney }}
      </el-form-item>
      <el-form-item label="优惠券金" prop="couponMoney">
        {{ form.couponMoney }}
      </el-form-item>
      <el-form-item label="实付金额" prop="payMoney">
        {{ form.payMoney }}
      </el-form-item>
      <el-form-item label="购物金" prop="shopMoney">
        {{ form.shopMoney }}
      </el-form-item>
      <el-form-item label="商品规格" prop="goodsAttr">
        {{ form.goodsAttr }}
      </el-form-item>
      <el-form-item label="规格编码" prop="skuCode">
        {{ form.skuCode }}
      </el-form-item>
      <el-form-item label="评论状态" prop="commentStatus">
        {{ form.commentStatus }}
      </el-form-item>
      <el-form-item label="状态" prop="status">
        {{ form.status }}
      </el-form-item>
      <el-form-item label="发货方式 ( 0普通快递 1无需物流）" prop="deliveryType">
        {{ form.deliveryType }}
      </el-form-item>
      <el-form-item label="邮费" prop="postagePrice">
        {{ form.postagePrice }}
      </el-form-item>
      <el-form-item label="发票类型" prop="invoiceType">
        {{ form.invoiceType }}
      </el-form-item>
      <el-form-item label="开票状态" prop="invoiceStatus">
        {{ form.invoiceStatus }}
      </el-form-item>
      <el-form-item label="买家留言" prop="buyerMsg">
        {{ form.buyerMsg }}
      </el-form-item>
      <el-form-item label="供应商" prop="supplierId">
        {{ form.supplierId }}
      </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="OrderItem">
  import { listOrderItem, getOrderItem, delOrderItem, addOrderItem, updateOrderItem } from "@/api/mall/orderItem";
  const { proxy } = getCurrentInstance();

  // 遮罩层
  const loading = ref(true);
  // 导出遮罩层
  const exportLoading = ref(false);
  // 选中数组
  const ids = ref([]);
  // 非单个禁用
  const single = ref(true);
  // 非多个禁用
  const multiple = ref(true);
  // 切换搜索条件
  const showSearch = ref(false);
  // 总条数
  const total = ref(0);
  // 订单子单表格数据
  const orderItemList = ref([]);
  // 弹出层标题
  const title = ref("");
  // 弹出层
  const open = ref(false);
  const open2 = ref(false);
  const data = reactive({
    // 列信息
    columns: [
      {key: 0, label: `订单子单ID`, visible: true},
      {key: 1, label: `订单子单编号`, visible: true},
      {key: 2, label: `订单ID`, visible: true},
      {key: 3, label: `支付单号`, visible: true},
      {key: 4, label: `客户`, visible: true},
      {key: 5, label: `商品`, visible: true},
      {key: 6, label: `规格Id`, visible: true},
      {key: 7, label: `一级品类`, visible: true},
      {key: 8, label: `二级品类`, visible: true},
      {key: 9, label: `三级品类`, visible: true},
      {key: 10, label: `商品名称`, visible: true},
      {key: 11, label: `商品图`, visible: true},
      {key: 12, label: `成本价`, visible: true},
      {key: 13, label: `售价`, visible: true},
      {key: 14, label: `购买数量`, visible: true},
      {key: 15, label: `订单总结`, visible: true},
      {key: 16, label: `优惠金额`, visible: true},
      {key: 17, label: `商品总价`, visible: true},
      {key: 18, label: `优惠券金`, visible: true},
      {key: 19, label: `实付金额`, visible: true},
      {key: 20, label: `购物金`, visible: true},
      {key: 21, label: `商品规格`, visible: true},
      {key: 22, label: `规格编码`, visible: true},
      {key: 23, label: `评论状态`, visible: true},
      {key: 24, label: `状态（0：待付款 1未发货 2已发货 3已收货 4退货售后 ）`, visible: true},
      {key: 25, label: `发货方式 ( 0普通快递 1无需物流）`, visible: true},
      {key: 26, label: `邮费`, visible: true},
      {key: 27, label: `发票类型（0：可开，1：不可开）`, visible: true},
      {key: 28, label: `开票状态（0未开票 1：申请中，2已开票）`, visible: true},
      {key: 29, label: `买家留言`, visible: true},
      {key: 30, label: `供应商`, visible: true},
      {key: 31, label: `创建时间`, visible: true},
      {key: 32, label: `更新时间`, visible: true},
      {key: 33, label: `操作`, visible: true},
    ],
    // 表单参数
    form:{},
    // 查询参数
    queryParams: {
      pageNum: 1,
      pageSize: 10,
      orderItemNo: null,
      orderId: null,
      payOrderNo: null,
      customerId: null,
      productId: null,
      goodsId: null,
      firstCategoryId: null,
      secondCategoryId: null,
      thirdCategoryId: null,
      productName: null,
      productImg: null,
      costPrice: null,
      salePrice: null,
      buyNum: null,
      orderTotalMoney: null,
      preMoney: null,
      payProductMoney: null,
      couponMoney: null,
      payMoney: null,
      shopMoney: null,
      goodsAttr: null,
      skuCode: null,
      commentStatus: null,
      status: null,
      deliveryType: null,
      postagePrice: null,
      invoiceType: null,
      invoiceStatus: null,
      buyerMsg: null,
      supplierId: null,
    },
    rules: {
    }
  });
  const { columns, queryParams, form, rules } = toRefs(data);

  /** 查询订单子单列表 */
  function getList() {
    loading.value = true;
    listOrderItem(queryParams.value).then(response => {
      orderItemList.value = response.rows;
      total.value = response.total;
      loading.value = false;
    });
  }
  /** 取消按钮 */
  function cancel() {
    open.value = false;
    open2.value = false;
    reset();
  }
  /** 表单重置 */
  function reset() {
    form.value = {
      orderItemId: null,
      orderItemNo: null,
      orderId: null,
      payOrderNo: null,
      customerId: null,
      productId: null,
      goodsId: null,
      firstCategoryId: null,
      secondCategoryId: null,
      thirdCategoryId: null,
      productName: null,
      productImg: null,
      costPrice: null,
      salePrice: null,
      buyNum: null,
      orderTotalMoney: null,
      preMoney: null,
      payProductMoney: null,
      couponMoney: null,
      payMoney: null,
      shopMoney: null,
      goodsAttr: null,
      skuCode: null,
      commentStatus: "0",
      status: "0",
      deliveryType: null,
      postagePrice: null,
      invoiceType: null,
      invoiceStatus: "0",
      buyerMsg: null,
      supplierId: null,
      createTime: null,
      updateTime: null,
    };
    proxy.resetForm("userForm");
  }
  /** 搜索按钮操作 */
  function handleQuery() {
    queryParams.value.pageNum = 1;
    getList();
  }

  /** 重置按钮操作 */
  function resetQuery() {
    proxy.resetForm("queryRef");
    handleQuery();
  }
  /** 切换按钮操作 */
  function changSearch() {
    showSearch.value = !showSearch.value;
  }
  /** 多选框选中数据 */
  function handleSelectionChange(selection) {
    ids.value = selection.map(item => item.orderItemId);
    single.value = selection.length != 1;
    multiple.value = !selection.length;
  }
  /** 新增按钮操作 */
  function handleAdd() {
    reset();
    open.value = true;
    title.value = "添加订单子单";
  }
  /** 修改按钮操作 */
  function handleUpdate(row) {
    reset();
    const orderItemId = row.orderItemId || ids.value
    getOrderItem(orderItemId).then(response => {
      form.value = response.data;
      open.value = true;
      title.value = "修改订单子单";
    });
  }
  /** 详情按钮操作 */
  function handleDetails(row) {
    reset();
    const orderItemId = row.orderItemId || ids.value
    getOrderItem(orderItemId).then(response => {
      form.value = response.data;
      open2.value = true;
      title.value = "修改订单子单";
    });
  }
  /** 提交按钮操作 */
  function submitForm() {
    proxy.$refs["orderItemForm"].validate(valid => {
      if (valid) {
        if (form.value.orderItemId) {
          updateOrderItem(form.value).then(response => {
            proxy.$modal.msgSuccess("修改成功");
            open.value = false;
            getList();
          });
        } else {
          addOrderItem(form.value).then(response => {
            proxy.$modal.msgSuccess("新增成功");
            open.value = false;
            getList();
          });
        }
      }
    })
  }
  /** 删除按钮操作 */
  function handleDelete(row) {
    const orderItemIds = row.orderItemId || ids.value;
    proxy.$modal.confirm('是否确认删除订单子单编号为\"' + orderItemIds + '\"的数据项?').then(() => {

      return delOrderItem(orderItemIds);
    }).then(() => {
      getList();
      proxy.$modal.msgSuccess("删除成功");
    }).catch(() => {});
  }
  /** 导出按钮操作 */
  function handleExport() {
    exportLoading.value = true;
    proxy.download("system/post/export", {
      ...queryParams.value
    }, `订单子单表_${new Date().getTime()}.xlsx`).then(response => {
      exportLoading.value = false;
    }).catch(error => {
      exportLoading.value = false;
    });
  }
  getList();
</script>
